package com.wc.alorithm_luogu.P1923;

import java.io.*;

/**
 * @Author congge
 * @Date 2023/5/7 10:01
 * @description https://www.luogu.com.cn/problem/P1923
 * 求第 k 小的数(快速排序的变种)
 */
public class Main {
    public static void main(String[] args) throws IOException {
        Input sc = new Input();
        int n = sc.nextInt();
        int k = sc.nextInt();


        int[] array = new int[n];

        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }


        Main main = new Main();
        main.quickSortByK(array, 0, n - 1, k);

        PrintWriter printWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        printWriter.println(array[k]);

        printWriter.flush();
        printWriter.close();
    }

    public void quickSortByK(int[] array, int left, int right, int k) {
        int mid = left + (right - left) / 2;
        int i = left;
        int j = right;

        do {
            while (array[i] < array[mid]) i++;
            while (array[j] > array[mid]) j--;
            if (i <= j) {
                swap(array, i, j);
                i++;
                j--;
            }
        } while (i <= j);

        if (k <= j) {
            quickSortByK(array, left, j, k);
        } else if (k >= i) {
            quickSortByK(array, i, right, k);
        }
    }

    public void swap(int[] array, int i, int j) {
        int tmp = array[i];
        array[i] = array[j];
        array[j] = tmp;
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
